package com.tfy.liquor.controller;

import com.tfy.liquor.bean.AdminUser;
import com.tfy.liquor.bean.Result;
import com.tfy.liquor.service.AdminUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/admin")
public class AdminUserController {
    private final static Logger logger = LoggerFactory.getLogger(AdminUserController.class);

    @Autowired
    private AdminUserService adminUserService;

    /**
     * 管理员登录验证
     *
     * @param adminUser
     * @param session
     * @return
     */
    @RequestMapping("/loginVerification")
    public Result loginVerification(HttpSession session, AdminUser adminUser) {
        try {
            Thread.sleep(500);
        } catch (Exception ignored) {
            logger.error("用户登录出错！");
        }
//        System.err.println(adminUser);
        AdminUser adminUser1 = adminUserService.getAdminUserInfo(adminUser);
//        AdminUser adminUser1 = null;
        if (null == adminUser1) {
            // 返回参数错误
            return new Result().error("账号或密码错误！");
        } else if (adminUser1.getStatus() == 1) {
            return new Result().error("账户已冻结！");
        }
        // 保存用户信息到session
        session.setAttribute("adminUser", adminUser1);
        return new Result().ok();
    }
}
